﻿using System;
using System.Xml.Linq;
using HigLabo.Net.Extensions;
using System.Collections.Generic;

namespace HigLabo.Net.Twitter
{
    /// <summary>
    /// 
    /// </summary>
    public class User : ResponseObject
    {
        /// <summary>
        /// 
        /// </summary>
        public String ProfileSidebarBorderColor { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String ProfileSidebarFillColor { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean ProfileBackgroundTile { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public DateTimeOffset CreatedAt { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String ProfileImageUrl { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Location { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean FollowRequestSent { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean IsTranslator { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String IDString { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String ProfileLinkColor { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public UserEntities Entities { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public String Url { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean DefaultProfile { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean ContributorsEnabled { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 FavouritesCount { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 UtcOffset { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public String ProfileImageUrlHttps { set; get; }
        /// <summary>
        /// 
        /// </summary>
        public Int64 ID { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 ListedCount { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean ProfileUseBackgroundImage { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String ProfileTextColor { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean Protected { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Language { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 FollowersCount { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean GeoEnabled { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean Verified { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean Notifications { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String Description { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String ProfileBackgroundColor { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String TimeZone { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String ProfileBackgroundImageUrlHttps { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String ProfileBackgroundImageUrl { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 StatusesCount { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean DefaultProfileImage { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Int32 FriendsCount { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean? ShowAllInlineMedia { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String ScreenName { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Boolean Following { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String WithheldInCountries { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public String WithheldScope { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public Status Status { get; set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public User(String jsonText)
        {
            if (!String.IsNullOrEmpty(jsonText))
            {
                this.SetProperty(jsonText);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="jsonText"></param>
        public override void SetProperty(string jsonText)
        {
            var d = this.SetData(jsonText);

            this.ContributorsEnabled = d.ToBoolean("contributors_enabled") ?? this.ContributorsEnabled;
            this.CreatedAt = d.CastToDateTimeOffset("created_at") ?? this.CreatedAt;
            this.DefaultProfile = d.ToBoolean("default_profile") ?? this.DefaultProfile;
            this.DefaultProfileImage = d.ToBoolean("default_profile_image") ?? this.DefaultProfileImage;
            this.Description = d.ToString("description");

            this.Entities = new UserEntities(d.ToString("entities"));

            this.FavouritesCount = d.ToInt32("favourites_count") ?? this.FavouritesCount;
            this.FollowRequestSent = d.ToBoolean("follow_request_sent") ?? this.FollowRequestSent;
            this.FollowersCount = d.ToInt32("followers_count") ?? this.FollowersCount;
            this.Following = d.ToBoolean("following") ?? this.Following;
            this.FriendsCount = d.ToInt32("friends_count") ?? this.FriendsCount;
            this.GeoEnabled = d.ToBoolean("geo_enabled") ?? this.GeoEnabled;
            this.ID = d.ToInt64("id") ?? 0;
            this.IDString = d.ToString("id_str");
            this.IsTranslator = d.ToBoolean("is_translator") ?? this.IsTranslator;
            this.Language = d.ToString("lang");
            this.ListedCount = d.ToInt32("listed_count") ?? this.ListedCount;
            this.Location = d.ToString("location");
            this.Name = d.ToString("name");
            this.Notifications = d.ToBoolean("notifications") ?? this.Notifications;
            this.ProfileBackgroundColor = d.ToString("profile_background_color");
            this.ProfileBackgroundImageUrl = d.ToString("profile_background_image_url");
            this.ProfileBackgroundImageUrlHttps = d.ToString("profile_background_image_url_https");
            this.ProfileBackgroundTile = d.ToBoolean("profile_background_tile") ?? this.ProfileBackgroundTile;
            this.ProfileImageUrl = d.ToString("profile_image_url");
            this.ProfileImageUrlHttps = d.ToString("profile_image_url_https");
            this.ProfileLinkColor = d.ToString("profile_link_color");
            this.ProfileSidebarBorderColor = d.ToString("profile_sidebar_border_color");
            this.ProfileSidebarFillColor = d.ToString("profile_sidebar_fill_color");
            this.ProfileTextColor = d.ToString("profile_text_color");
            this.ProfileUseBackgroundImage = d.ToBoolean("profile_use_background_image") ?? this.ProfileUseBackgroundImage;
            this.Protected = d.ToBoolean("protected") ?? this.Protected;
            this.ScreenName = d.ToString("screen_name");
            this.ShowAllInlineMedia = d.ToBoolean("show_all_inline_media");

            this.StatusesCount = d.ToInt32("statuses_count") ?? this.StatusesCount;
            this.TimeZone = d.ToString("time_zone");
            this.Url = d.ToString("url");
            this.UtcOffset = d.ToInt32("utc_offset") ?? this.UtcOffset;
            this.Verified = d.ToBoolean("verified") ?? this.Verified;
            this.WithheldInCountries = d.ToString("withheld_in_countries");
            this.WithheldScope = d.ToString("withheld_scope");
            this.Status = new Status(d.ToString("status"));
        }
        
    }
}
